<template>
  <div>
    <ul>
      <li v-for="message in messages" :key="message.id">
        <!--路由传参及使用命名路由配置写法-->
<!--        <router-link
          :to="{
            name:'detail', //使用命名路由时,需要将path属性换为name属性
            query:{
              id:message.id,
              title:message.title
            }
          }"
        >
          {{'message'+message.id}}
        </router-link>&nbsp;&nbsp;-->
        <!--路由使用params属性行内模板写法-->
<!--        <router-link :to="`/home/message/detail/${message.id}/${message.title}`">
          {{'message'+message.id}}
        </router-link>&nbsp;&nbsp;-->
        <!--路由使用params属性对象写法-->
        <router-link :to="{
          name:'detail',
          params:{
            id:message.id,
            title:message.title
          }
        }">
          {{'message'+message.id}}
        </router-link>&nbsp;&nbsp;
        <button @click="pushShow(message)">使用push查看</button>
        <button @click="replaceShow(message)">使用replace查看</button>
      </li>
    </ul>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: "Message",
  data(){
    return{
      messages:[
        {id:'001',title:'消息001'},
        {id:'002',title:'消息002'},
        {id:'003',title:'消息003'}
      ]
    }
  },
  methods:{
    pushShow(message){
      this.$router.push({
        name:'detail',
        params:{
          id:message.id,
          title:message.title
        }
      })
    },
    replaceShow(message){
      this.$router.replace({
        name:'detail',
        params:{
          id:message.id,
          title:message.title
        }
      })
    },
  },
  beforeDestroy() {
    console.log("Message组件即将销毁...")
  },
  activated() {
    console.log("Message组件被激活...")
  },
  deactivated() {
    console.log("Message组件失活...")
  }
}
</script>

<style scoped>

</style>